
from apps import dbUtil

# 给数据库添加新的标点GPS位置 本方法目前只用于app.py的socketIO的使用
# from apps.path.pathService import insertPath
from apps.path import pathService
from apps import dbUtil


# 将GPS数据存入数据库
def save_gps(path_id, gps):
    db = dbUtil.getDbConnection()
    cursor = db.cursor()
    # 找出最大的gps_id
    cursor.execute("select max(gps_ID) from gps")
    db_res = cursor.fetchall()
    if db_res[0][0] is None:
        gps_id = 1
    else:
        gps_id = int(db_res[0][0])+1
    cursor.execute("insert into gps(GPS_ID, longitude, latitude, path_ID) value('{}', '{}', '{}', '{}')".format(gps_id, gps[0], gps[1], path_id))
    db.commit()
    cursor.close()
    db.close()
    return gps_id


if __name__ == '__main__':
    save_gps('2', [11, 12])
    pass
